package com.sxj.corejava.code09_集合.List;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 石小俊
 * @date 2025年02月19日
 * 创建5名Student对象(属性:no、score),然后放到ArrayList集合中
 * 学生学号为:1-5,成绩随意
 * 1.遍历集合,删除学号为2的学生
 * 2.不遍历集合,删除学号为3的学生
 * 3.不遍历集合,判断集合中是否包含学号为5的学生
 */
public class Test06_练习 {
    public static void main(String[] args) {
        Student student = new Student("1", 80.0);
        Student student2 = new Student("2", 90.0);
        Student student3 = new Student("3", 95.0);
        Student student4 = new Student("4", 88.0);
        Student student5 = new Student("5", 50.0);
        List<Student> students = new ArrayList<>(Arrays.asList(student, student2, student3, student4, student5));
        System.out.println(students);

        // 1.遍历集合,删除学号为2的学生
        for (int i = students.size() - 1; i >= 0; i--) {
            Student stu = students.get(i);
            if ("2".equals(stu.getNo())) {
                students.remove(i);
            }
        }
        System.out.println("遍历集合,删除学号为2的学生之后:" + students);

        // 2.不遍历集合,删除学号为3的学生
        Student stu = new Student();
        stu.setNo("3");
        students.remove(stu);
        System.out.println("不遍历集合,删除学号为3的学生之后:" + students);

        // 3.不遍历集合,判断集合中是否包含学号为5的学生
        Student stu2 = new Student();
        stu2.setNo("5");
        System.out.println("不遍历集合,判断集合中是否包含学号为5的学生:" + students.contains(stu2));
    }
}
